#include "Character.h"


void Character::DrawTo(Bitmap* renderTarget, const bool specialActive, const int x, const int y)
{
	if(isActive())
	{
		if(specialActive)
			this->mSpecImage->DrawTo(renderTarget, x + mXcoord, y + mYcoord);
		else
			this->mImage->DrawTo(renderTarget, x + mXcoord, y + mYcoord);
	}
}
void Character::DrawTo(Bitmap* renderTarget, const int x, const int y)
{
	if(isActive())
	{
		this->mImage->DrawTo(renderTarget, x + mXcoord, y + mYcoord);
	}
}

void Character::move(Background* bg)
{ 
	mMoveBehavior->perform(this, bg);
}
void Character::moveTo(const Background* bg, BackgroundElement* nTile)
{
	setCoord(nTile->getXcoord(), nTile->getYcoord());
	setTileIndex(bg->getIndex(nTile));
	setCurrTile(nTile);

	setupProximity(bg, nTile);		
}

void Character::setupProximity(const Background* bg, BackgroundElement* tile)
{
	int row		  = bg->getRow  (tile),
		col		  = bg->getCol  (tile);
	int tileIndex = bg->getIndex(tile);

	mAdjacentTiles[UP]   = (row == 0)? 
		/*last row, same col*/		bg->getTile(NUM_TILES-(bg->tilesPerBase()-col)) : 
									bg->getTile(tileIndex-bg->tilesPerBase());
	mAdjacentTiles[DOWN] = (row == bg->tilesPerHeight()-1)?
		/*first row, same col*/		bg->getTile(col) :
									bg->getTile(tileIndex+bg->tilesPerBase());
	mAdjacentTiles[RIGHT]= (col == bg->tilesPerBase()-1)? 
		/*same row, last col*/		bg->getTile(tileIndex-(bg->tilesPerBase()-1)) : 
									bg->getTile(tileIndex+1);
	mAdjacentTiles[LEFT] = (col == 0)?
		/*same row, first col*/		bg->getTile(tileIndex+(bg->tilesPerBase()-1)) :
									bg->getTile(tileIndex-1);
}
